package tomsung.cloud.agdc.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tomsung.cloud.agdc.bean.Temperature;
import tomsung.cloud.agdc.dao.TemperatureMapper;

@Service("TemperatureService")
public class TemperatureService {

	@Autowired
	TemperatureMapper temperatureMapper;
	
	public synchronized int createTemperatureData(Temperature record)
	{
		return temperatureMapper.insertSelective(record);
	}
	
	public int deleteTemperatureData(Integer groupid)
	{
		return temperatureMapper.deleteByPrimaryKey(groupid);
	}
	
	public Temperature selectTemperatureData(Integer groupid)
	{
		return temperatureMapper.selectByPrimaryKey(groupid);
	}
	
	public int updateTemperatureData(Temperature record)
	{
		return temperatureMapper.updateByPrimaryKey(record);
	}
	
	public List<Temperature> getTempDataBySystemId(List<Long> systemIds, Date beginTime, Date endTime, int devType)
	{
		List<Temperature> temps = new ArrayList<Temperature>();
		for (Long id : systemIds)
		{
			List<Temperature> ts = temperatureMapper.getTempDataBySysetemId(id, beginTime, endTime, devType);
			if (ts != null && ts.size() > 0)
			{
				temps.addAll(ts);
			}
		}
		return temps;
	}
}
